	
	
  global data Z:\STATA files
  global outputDS Z:\Figures\Descriptive
  global export Z:\Figures
  
  *************************************
  * Appendix C2 (Belgium)
  ************************************
  
  
  *dataset created in Appendix_D4.do using raw files 
  
  use "$data/paneldetachement_full_final.dta", clear
  g freq=1
  collapse freq, by(Klant_ID Werkgever_ID year)
  bys year: sum freq, d 
  replace  Klant_ID=99999 if  Klant_ID==4153134529 
  collapse (sum) freq, by(year Werkgever_ID) 
  collapse (mean) freq, by(year)
  drop if year==.
   twoway (connected freq year), graphregion(fcolor(white) lcolor(white)) ///
   xlabel(2010 (1) 2020, angle(vertical)) ytitle("Average Number of Clients by Foreign Service Provider") ///
   xtitle("")
   graph export "$export/KlantID_byWergever_peryear.png", replace

  use "$data/paneldetachement_full_final.dta", clear
  g freq=1
  collapse (sum) freq, by(Klant_ID year)
  g count=1
  egen panel=sum(count), by(Klant_ID )
  collapse (mean) panel (min) year, by(Klant_ID)
  save "$data/Klant_ID_persistance.dta", replace
  
  hist panel, frac ///
  xtitle("Number of Years With Postings>0") ///
  graphregion(fcolor(white) lcolor(white))
  graph export "$export/posting_persistance_KlantID.png", replace
  
  hist year, frac ///
  xtitle("First Year of Posting Use") ///
  graphregion(fcolor(white) lcolor(white))
  graph export "$export/posting_persistance_KlantID_byfirstyear.png", replace
  
  hist panel if year==2010, frac ///
  xtitle("Number of Years With Postings>0") ///
  graphregion(fcolor(white) lcolor(white)) ///
  subtitle("Posting Use Persistance for Receiving Firms that Started Using Posting in 2010", size(small))
  graph export "$export/posting_persistance_KlantID_2010.png", replace
 
  
  use "$data/paneldetachement_full_final.dta", clear
  g freq=1
  collapse (sum) freq, by(Klant_ID year)
  g count=1
  egen panel=sum(count), by(Klant_ID )
  
  
  *Figure C17
  xtile rank=freq  , nq(10)
  
  collapse (mean) freq panel, by(Klant_ID)
    xtile rank=freq  , nq(10)
	binscatter rank panel, ///
	xtitle("Number of Years of Posting Use") ytitle("Decile of Posting Use") ylabel(0 (2) 10)
    graph export "$export/rankpanel.png", replace
		 
		 
   use "$data/paneldetachement_full_final.dta", clear
   g freq=1
   collapse (sum) freq, by(Klant_ID Werkgever_ID year)
   egen max_freq=max(freq), by(Klant_ID )
   
   
   drop if  Klant_ID==4153134529 
   keep if freq==max_freq
   duplicates tag Klant_ID, g(flag)
   *for now 
   drop if flag>0
   drop year
   save "$data/mainsupplier.dta", replace
   *fichier avec le main supplier par client belge 
   
   use "$data/paneldetachement_full_final.dta", clear
   g freq=1
   collapse (sum) freq, by(Klant_ID Werkgever_ID  year)
   g count=1 
   collapse (sum) count, by(Klant_ID Werkgever_ID)
   rename count panel_main
   merge 1:1 Werkgever_ID Klant_ID using "$data/mainsupplier.dta"
   keep if _m==3
   drop _m
   merge 1:1 Klant_ID using "$data/Klant_ID_persistance.dta"
   keep if _m==3
   collapse (mean) panel_main,by(panel)
   g n_label=round(panel_main,0.1)
   
   
   twoway (connected  panel_main panel, mlabel(n_label) mlabgap(*1) mlabposition(12)), ///
   xtitle("Number of Years with Postings>0") ytitle("Year") ///
   graphregion(fcolor(white) lcolor(white)) xlabel(1 (1) 11) ylabel(0 (2) 4) ///
   subtitle("Length of the Relation between Domestic Client and Main Foreign Supplier", size(medsmall))
    graph export "$export/clientsupplier_persistance.pdf", replace
		 
		 
		 **********************************************************************
		 
		 		 
   use "$data/paneldetachement_full_final.dta", clear
   g freq=1
   collapse (sum) freq, by(Klant_ID country_employer year)
   egen max_freq=max(freq), by(Klant_ID )
   
   
   drop if  Klant_ID==4153134529 
   keep if freq==max_freq
   duplicates tag Klant_ID, g(flag)
   *for now 
   drop if flag>0
   drop year
   save "$data/mainsupplier_country.dta", replace
   *fichier avec le main supplier par client belge 
   
   use "$data/paneldetachement_full_final.dta", clear
   g freq=1
   collapse (sum) freq, by(Klant_ID country_employer  year)
   g count=1 
   collapse (sum) count, by(Klant_ID country_employer)
   rename count panel_main
   merge 1:1 country_employer Klant_ID using "$data/mainsupplier_country.dta"
   keep if _m==3
   drop _m
   merge 1:1 Klant_ID using "$data/Klant_ID_persistance.dta"
   keep if _m==3
   collapse (mean) panel_main,by(panel)
   g n_label=round(panel_main,0.1)
   
   *Figure C18   
   twoway (connected  panel_main panel, mlabel(n_label) mlabgap(*1) mlabposition(12)), ///
   xtitle("Number of Years with Postings>0") ytitle("Year") ///
   graphregion(fcolor(white) lcolor(white)) xlabel(1 (1) 11) ylabel(0 (2) 11) ///
   subtitle("Length of the Relation between Domestic Client and Main Trading Partner", size(medsmall))
   graph export "$export/clientsupplier_persistance_country.png", replace
		 
		 